package com.Map集合.练习01;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashMapDemo {
/*
001号学生 Student(name=张飞, age=25)
002号学生 Student(name=黄忠, age=40)

 */
    public static void main(String[] args) {
        Student student = new Student("张飞",25);
        Student student2 = new Student("黄忠",40);

        //创建集合对象
        HashMap<String, Student> hashMap = new HashMap<>();
        hashMap.put("001",student);
        hashMap.put("002",student2);

        //遍历集合
        Set<Map.Entry<String, Student>> entries = hashMap.entrySet();
        for (Map.Entry<String, Student> entry : entries) {
            Student value = entry.getValue();
            String key = entry.getKey();
            System.out.println(key+"号"+"学生 "+value);
        }

    }
}
